<template>
	<Table :Config="Config"></Table>

	<div>
		<a-drawer v-model:visible="tree_visible" title="权限菜单" placement="right" :footer-style="{ textAlign: 'right' }">
			<a-tree v-model:expandedKeys="expandedKeys" v-model:selectedKeys="selectedKeys" v-model:checkedKeys="checkedKeys" checkable :tree-data="treeData" :defaultExpandAll="true" v-if="treeData.length > 0"> </a-tree>
			<template #footer>
				<a-button style="margin-right: 8px" @click="onClose">取消</a-button>
				<a-button type="primary" @click="fun_set_role">提交</a-button>
			</template>
		</a-drawer>
	</div>
</template>
<script>
var dict_IsDel = [
	{ value: 0, label: '正常' },
	{ value: 1, label: '删除' },
];

var columns = [
	{ title: '自增id', dataIndex: 'role_id', iskey: true, width: 80, hidden: false, add: false, edit: false, type: 'int' },

	{ title: '添加时间', dataIndex: 'addtime', iskey: false, width: 165, hidden: true, add: false, edit: false, type: 'datetime' },
	{ title: '添加时间戳', dataIndex: 'addtime_stamp', iskey: false, width: 150, hidden: true, add: false, edit: false, type: 'long' },
	{ title: '添加用户', dataIndex: 'add_userid', iskey: false, width: 150, hidden: true, add: false, edit: false, type: 'int' },
	{ title: '修改时间', dataIndex: 'update_lasttime', iskey: false, width: 165, hidden: true, add: false, edit: false, type: 'datetime' },
	{ title: '修改时间戳', dataIndex: 'update_lasttime_stamp', iskey: false, width: 150, hidden: true, add: false, edit: false, type: 'long' },
	{ title: '最后修改人', dataIndex: 'last_userid', iskey: false, width: 150, hidden: true, add: false, edit: false, type: 'int' },
	{ title: '是否删除', dataIndex: 'isdel', iskey: false, width: 150, hidden: true, add: false, edit: false, type: 'int' },

	{ title: '角色名称', dataIndex: 'role_name', iskey: false, width: 300, hidden: false, add: true, edit: true, type: 'string' },
	{ title: '操作', dataIndex: 'action', hidden: false, add: false, edit: false },
	//{ title: '-', dataIndex: '占位' },
];

export default {
	components: {},
	data() {
		return {
			Config: {
				getPageUrl: '/manage/SystemRole/GetListByPage',
				getUrl: '/manage/SystemRole/GetById',
				addUrl: '/manage/SystemRole/Insert',
				editUrl: '/manage/SystemRole/Update',
				delUrl: '/manage/SystemRole/DeleteById',

				columns: columns,
				page: 1,
				pageSize: 15,

				navList: [
					{ to: '/', name: '首页' },
					{ to: '/', name: '用户' },
					{ to: '', name: '权限管理' },
				],
				action: [{ name: '菜单权限', funName: 'fun_Event1', type: false }],
			},
			tree_visible: false,
			checkedKeys: [],
			treeData: [],
			role_id: 0,
		};
	},
	mounted() {
		var that = this;
		that.$http.post('/manage/SystemMenu/GetListTree', {}, that, function (ret) {
			that.treeData = ret.Data;
		});
	},
	methods: {
		async fun_Event1(record) {
			var that = this;
			that.tree_visible = true;
			that.role_id = record.role_id;

			var userRoleIDs = await that.$http.post('/manage/SystemRoleMenuLink/GetListByRoleID', { ID: that.role_id }, that);
			that.checkedKeys = userRoleIDs.Data;
		},
		onClose() {
			debugger;
			this.tree_visible = false;
			this.treeData = [];
			this.checkedKeys = [];
		},
		fun_set_role() {
			var that = this;
			var ret = that.$http.post('/manage/SystemRoleMenuLink/BatchAdd', { role_id: that.role_id, MenuIDs: that.checkedKeys }, that, function (ret) {
				that.$Message['success']({ background: true, duration: 1, content: '请求成功' });
			});
			this.tree_visible = false;
		},
	},
};
</script>
